

#import "UIView+XBKit.h"


@implementation UIView (XBKit)

-(CGFloat)width
{
    return self.frame.size.width;
}
-(void)setWidth:(CGFloat)width
{
    CGRect myFrame = self.frame;
    myFrame.size.width = width;
    self.frame = myFrame;
}
-(CGFloat)height
{
    return self.frame.size.height;
}

-(void)setHeight:(CGFloat)height
{
    CGRect myFrame = self.frame;
    myFrame.size.height = height;
    self.frame = myFrame;
}
-(CGFloat)x
{
    return self.frame.origin.x;
}

-(void)setX:(CGFloat)x
{
    CGRect myFrame = self.frame;
    myFrame.origin.x = x;
    self.frame = myFrame;
}
-(CGFloat)y
{
    return self.frame.origin.y;
}

-(void)setY:(CGFloat)y
{
    CGRect myFrame = self.frame;
    myFrame.origin.y = y;
    self.frame = myFrame;
}
-(CGSize)size
{
    return self.frame.size;
}

-(void)setSize:(CGSize)size
{
    CGRect frame = self.frame;
    frame.size = size;
    self.frame = frame;
}
-(CGFloat)centerX
{
    return self.center.x;
}

-(void)setCenterX:(CGFloat)centerX
{
    CGPoint pointCenter = self.center;
    pointCenter.x = centerX;
    self.center = pointCenter;
}

-(CGFloat)centerY
{
    return self.center.y;
}
-(void)setCenterY:(CGFloat)centerY
{
    CGPoint pointCenter = self.center;
    pointCenter.y = centerY;
    self.center = pointCenter;
}

-(CGPoint)point
{
    
    return CGPointMake(self.frame.origin.x  + self.frame.size.width/2, self.frame.origin.y + self.frame.size.height/2);
    
}

-(void)setPoint:(CGPoint)point
{
    CGRect frame = self.frame;
    frame.origin = point;
    self.frame = frame;
    
    
    
}

- (void)setRoundedcorners:(CGFloat)size{
    
    
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = size;
    
}
/**
 *  设置圆角 默认5
 */
- (void)setRoundedcornersDefault{
    
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = 5;
    
}

- (void)setBorderDefault {
    
    [self setBorderWithBorderColor:[UIColor lightGrayColor] andBorderWidth:1];
}

- (void)setBorderWithBorderColor:(UIColor *)borderColor andBorderWidth:(CGFloat)borderWidth{
    
    self.layer.borderColor = borderColor.CGColor;
    self.layer.borderWidth = borderWidth;
}


+ (UIImage *)getImageFromView:(UIView *)theView
{
    //UIGraphicsBeginImageContext(theView.bounds.size);
    UIGraphicsBeginImageContextWithOptions(theView.bounds.size, YES, theView.layer.contentsScale);
    [theView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

@end
